package Ep04_String._0028;

/**
 * @author Jimmy Zhan WORKSTATION
 * @date 2023/3/21 21:33
 * 说明：力扣 0028 找出字符串中第一个匹配项的下标：暴力解法
 */

public class Mine {
    public static void main(String[] args) {
        Mine m = new Mine();
        String haystack = "mississippi";
        String needle = "issipi";
        System.out.println(m.strStr(haystack, needle));
    }
    public int strStr(String haystack, String needle) {
        for (int i = 0; i < haystack.length(); i++) {
            int point = i;
            for (int j = 0; j < needle.length(); j++) {
                if (point >= haystack.length()){
                    break;
                }
                if (needle.charAt(j) != haystack.charAt(point)){
                    break;
                }
                if (needle.charAt(j) == haystack.charAt(point)){
                    if (j == needle.length()-1){
                        return i;
                    }
                    point++;
                }

            }
        }
        return -1;
    }
}
